<script setup lang='ts'>
import { onMounted, ref } from "vue"
import { getShopNav } from "@/api/index"
import router from "@/router";
import { useRouter } from 'vue-router'
import LoadingPage from "@/components/LoadingPage.vue";
const $router = useRouter()
const lineName = ref<any>('精选');
const shopNav = ref<any>([]);
const isloading = ref<boolean>(true)
const toDifferentNavPage = (event: any) => {
    if (event.name == '精选') {
        router.push({ path: '/shop/cherry-pick', query: { uuid: event.id, nav: '精选' } });
        lineName.value = '精选';
    } else if (event.name == '免费') {
        router.push({ path: '/shop/free', query: { uuid: event.id, nav: '免费' } });
        lineName.value = '免费';
    } else if (event.name == '男生') {
        router.push({ path: '/shop/man', query: { uuid: event.id, nav: '男生' } });
        lineName.value = '男生';
    } else if (event.name == '女生') {
        router.push({ path: '/shop/women', query: { uuid: event.id, nav: '女生' } });
        lineName.value = '女生';
    } else if (event.name == '出版') {
        router.push({ path: '/shop/public', query: { uuid: event.id, nav: '出版' } });
        lineName.value = '出版';
    } else if (event.name == '听书') {
        router.push({ path: '/shop/listen', query: { uuid: event.id, nav: '听书' } });
        lineName.value = '听书';
    }
}
onMounted(async () => {
    let res = await getShopNav();
    shopNav.value = res.data.data.navi;
    if (router.currentRoute.value.query.nav) {
        lineName.value = router.currentRoute.value.query.nav
    }
    isloading.value = false
})

</script>

<template>

    <LoadingPage v-if="isloading" />
    <div class="shop" v-else>
        <div class="shop-search">
            <div class="search" @click="$router.push('/search')">
                <input type="text" placeholder="唐诗里的烟火人间">
                <img src="@/assets/imgs/搜索_o.png" alt="">
            </div>
        </div>
        <div class="shop-nav">
            <ul class="list">
                <li v-for="n in shopNav" :key="n.id" @click="toDifferentNavPage(n)">
                    <span :class="{ bold: n.name == lineName }">{{ n.name }}</span>
                    <span class="line" v-if="n.name == lineName"></span>
                </li>
            </ul>
        </div>
        <div class="content">
            <Transition name="shop">
                <router-view></router-view>
            </Transition>
        </div>
    </div>

</template>

<style lang="less" scoped>
.shop-enter-active,
.shop-leave-active {
    transition: all 0.2s;
}

.shop-enter-from {
    transform: translateX(100vw);
}

.shop-enter-to,
.shop-leave-from {
    transform: translateX(0);
}

.shop-leave-to {
    transform: translateX(-100vw);
}

img {
    width: 20rem;
}


.shop {
    padding: 0 15rem;
    padding-top: 20rem;

    .shop-search {
        display: flex;
        justify-content: space-between;
        align-items: center;

        .gender-logo {
            box-shadow: 0 0 5rem 0rem #ccc;
            width: 30rem;
            height: 30rem;
            border-radius: 15rem;
            display: flex;
            justify-content: center;
            align-items: center;
        }

        .search {
            width: 90vw;
            height: 30rem;
            display: flex;
            box-shadow: 0 0 6rem -1rem #ccc;
            border-radius: 20rem;
            overflow: hidden;

            input {
                flex-grow: 1;
                border: none;
                text-indent: 1em;
                outline: none;
            }

            img {
                width: 25rem;
                height: 25rem;
                margin-right: 6rem;
            }
        }
    }

    .shop-nav {
        margin: 12rem 0 8rem;

        ul.list {
            display: flex;
            justify-content: space-between;
            align-items: center;

            li {
                display: flex;
                flex-direction: column;
                justify-content: center;
                align-items: center;

                span {
                    font-size: 16rem;

                    &.bold {
                        color: #000;
                        font-weight: bold;
                    }

                    &.line {
                        margin-top: 2rem;
                        display: flex;
                        width: 12rem;
                        height: 2rem;
                        background-color: #fc1c1c;
                    }
                }

            }
        }
    }

    .content {
        width: 100%;
        height: calc(100vh - 158rem);
        overflow: auto;
    }
}
</style>
